<?php


namespace app\merchant\controller\setting;

use app\common\controller\BaseController;
use app\common\model\setting\SettingPriceRangeModel;
use app\common\service\product\ShopProductTypeService;
use app\common\service\setting\SettingPriceRangeService;
use app\common\service\setting\SettingStorePlatformService;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("价格区间")
 * @Apidoc\Group("setting")
 * @Apidoc\Sort("250")
 */
class SettingPriceRange extends BaseController
{
    public function list()
    {
        $where = $this->buildWhere([
            'is_disable',
            'status',
            'platform_ids',
            'product_type_ids',
        ]);
        $where = $this->where(where_delete($where));
        $where[] = ['is_disable','=',0];
        $data = SettingPriceRangeService::list($where,0, 0, $this->order());
        return success($data);
    }
    /**
     * @Apidoc\Title("查询评论佣金与追评")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\setting\SettingPriceRangeModel", field="user_consumption")
     */
    public function getComments()
    {
        //查询好评信息
        $comment_where[] = ['is_disable','<>',1];
        $comment_where[] = ['status','in',[2,3]];
        $comment_where[] = ['comment_type','in',[
            SettingPriceRangeModel::getCommentType('WZPJ',2),
            SettingPriceRangeModel::getCommentType('TWPJ',2),
            SettingPriceRangeModel::getCommentType('SPPJ',2),
        ]];
        $data = SettingPriceRangeService::getPriceRange(where_delete($comment_where));
        $list = $data['result'];
        foreach ($list as $key=>$val){
            $list[$key]['comment_type'] =(int)$val['comment_type'];
            $list[$key]['comment_type_str'] = SettingPriceRangeModel::getCommentType($val['comment_type'],1);
            $list[$key]['comment_type_code'] = SettingPriceRangeModel::getCommentType($val['comment_type'],3);
        }
        return success($list);
    }

    /**
     * 查询页面所需参数
     * @Author: 易军辉
     * @DateTime:2024-07-16 20:43
     */
    public function getParams()
    {
        $where = $this->where(where_delete());
        //店铺平台
        $store_platform_list = SettingStorePlatformService::list($where,0,0, $this->order(),'id as value,title as label,is_disable as disable');
        $product_type_list = ShopProductTypeService::list($where,0,0, $this->order(),'id,id as value,title as label,is_disable as disable');
        return success(compact('store_platform_list','product_type_list'));
    }
}
